package com.googlecode.yoohoo.xmppcore;

import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

import com.googlecode.yoohoo.xmppcore.protocol.InvalidJabberIdException;
import com.googlecode.yoohoo.xmppcore.protocol.JabberId;


public class JabberIdTest {
	private JabberId jid;
	
	private String jidString1;
	private String jidString2;
	private String jidString3;
	private String jidString4;
	
	@Before
	public void setUp() throws Exception {
		jidString1 = "roger@quicklinker.com/default";
		jidString2 = "roger@quicklinker.com";
		jidString3 = "quicklinker.com";
		jidString4 = "quicklinker.com/default";
		jidString4 = "roger@quicklinker@com/default";
		
	}
	
	@Test
	public void testFromJidString() {
		jid = JabberId.parseJidString(jidString1);
		Assert.assertEquals("roger", jid.getNode());
		Assert.assertEquals("quicklinker.com", jid.getDomain());
		Assert.assertEquals("default", jid.getResource());
		
		jid =  JabberId.parseJidString(jidString2);
		Assert.assertEquals("roger", jid.getNode());
		Assert.assertEquals("quicklinker.com", jid.getDomain());
		Assert.assertEquals(null, jid.getResource());
		
		jid =  JabberId.parseJidString(jidString3);
		Assert.assertEquals(null, jid.getNode());
		Assert.assertEquals("quicklinker.com", jid.getDomain());
		Assert.assertEquals(null, jid.getResource());
		
		try {
			jid = JabberId.parseJidString(jidString4);
			Assert.fail("Should throw an exception");
		} catch (InvalidJabberIdException e) {
			// should execute to here
		}
	}
}
